<?php
/**
 * szk 2022/7/17
 * 前台优惠券类
 */

namespace App\Http\Controllers\api;

use App\Http\Controllers\Controller;
use App\Repository\RepositoryInterface\CouponInterface;
use Illuminate\Http\Request;

class DiscountCouponController extends Controller
{
    protected $storeCoupon;

    public function __construct(CouponInterface $storeCoupon)
    {
        $this->storeCoupon = $storeCoupon;
    }


    /**
     * szk
     * 用户使用优惠券
     * @id 数组
     * @uid 用户
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function checkStatus(Request $request)
    {
        $discountData = $request->post('issueCouponId');
        $uid = $request->post('uid');
        return $this->storeCoupon->checkStatus($uid,$discountData);
    }

    /**
     * 根据商品获取优惠券
     * @param $id
     * @return mixed
     */
    public function productDiscount($id)
    {
        return $this->storeCoupon->productDiscount($id);
    }

    /**
     * 获取所有可用的优惠券
     * @return mixed
     */
    public function goodsDiscount()
    {
        return $this->storeCoupon->goodsDiscount();
    }

    /**
     * 用户根据商品选择可用优惠卷
     * @param Request $request
     * @return mixed
     */
    public function goodsChange(Request $request)
    {
        $goodsId = $request->get('goodsId');
        $uid = $request->get('uid');
        return $this->storeCoupon->goodsChange($uid, $goodsId);
    }

    /**
     * 查询个人优惠券
     * @param Request $request\
     * @return mixed
     */
    public function userCoupon(Request $request)
    {
        $id = $request->get('id');
        return $this->storeCoupon->userCoupon($id);
    }
    /**
     * 查询个人已使用/未使用/已过期优惠券
     * @param Request $request
     * @param $id
     * @return mixed
     */
    public function userList(Request $request)
    {
        $id = $request->get('id');
        $status = $request->get('status');
        return $this->storeCoupon->myList($id, $status);
    }

}
